# -*- coding: utf-8 -*-
__author__ = 'liubei'

import sqlite3

def exe(file, isSmoke, isHypertension):
    for line in open(file):
        items = line.split(",")
        for i in range(0, len(items), 2):
            print items[i]
            print items[i + 1]
            cx = sqlite3.connect("short_msg_stratergy.db")
            cx.execute("insert into short_msg_stratergy values (?,?,?,?)", (items[i], items[i + 1], isSmoke, isHypertension))
            cx.commit()


def db():
    cx = sqlite3.connect("short_msg_stratergy.db")
    cx.execute("create table short_msg_stratergy (day integer,sms_no varchar(10), isSmoke integer, isHypertension integer)")

def db2():
    cx = sqlite3.connect("short_msg_stratergy.db")
    cx.execute("create table short_msg (unique_id varchar,sms_no varchar(10), language varchar, type varchar, category_en varchar, category varchar, content varchar)")


def exemsg(file):
    for line in open(file):
        print line.split(";")
        unique_id, no, language, type, category_en, category, content = line.split(";")
        cx = sqlite3.connect("short_msg_stratergy.db")
        cx.execute("insert into short_msg values (?,?,?,?,?,?,?)", (unique_id, no, language, type, category_en, category.decode('utf-8'), content.decode('utf-8')))
        cx.commit()
        print content.decode('utf-8')


if __name__ == '__main__':
    # db()
    # exe("sh.csv", 1, 1)
    # exe("nsh.csv", 0, 1)
    # exe("snh.csv", 1, 0)
    # exe("nsnh.csv", 0, 0)
    # db2()
    exemsg('shortmsg.csv')